# import pygame and python modules
import pygame, math
from pygame.locals import *
from vector2 import *
from KeyboardHandler import *

# main player class
class Player(pygame.sprite.Sprite):
    "this is the player sprite"
    # constants
    SCREEN_RECT = (0, 0, 640, 480)
    size = (40, 40)
    normal_speed = 3
    back_speed = 2
    side_speed = 2.5
    run_speed = 4
    images = []

    def __init__(self, *initial_position):
        "supply initial position"
        pygame.sprite.Sprite.__init__(self, self.containers)        
        self.original_image = self.images[0]        
        self.rotation = 0
        self.rect = self.original_image.get_rect(center = initial_position)
        self.alive = True
        self.health = 100
        self.keyboard = KeyboardHandler()
        self.mouse_over = False

##    def check_screen_bounds(self, "SCREENSIZE")
##
##    def check_under_attack(self, "ZOMBIE_RECT")
##
##    def check_health(self, "DAMAGE")
##
##    def check_alive(self)
##
    def check_mouse_input(self, mouse):
        "takes current mouse position"
        self.mouse_position = mouse
        self.rotation = Vector2.get_angle(self.rect.center, self.mouse_position)
        self.image = pygame.transform.rotozoom(self.original_image, self.rotation, 1)
        self.rect = self.image.get_rect(center = self.rect.center)
           
    def move(self, keyboardHandler):
        if self.rect.collidepoint(self.mouse_position):
            self.mouse_over = True
        else:
            self.mouse_over = False
        self.keyboard = keyboardHandler
        if self.keyboard.up == True and self.mouse_over == False:
            headingX = math.sin(self.rotation * (math.pi / 180))
            headingY = math.cos(self.rotation * (math.pi / 180))
            heading = (-headingX * self.normal_speed, -headingY * self.normal_speed)
            self.rect.move_ip(heading)
        if self.keyboard.down == True and self.mouse_over == False:
            headingX = math.sin(self.rotation * (math.pi / 180))
            headingY = math.cos(self.rotation * (math.pi / 180))
            heading = (headingX * self.back_speed, headingY * self.back_speed)
            self.rect.move_ip(heading)
        if self.keyboard.left == True and self.mouse_over == False:
            headingX = math.sin((self.rotation + 90) * (math.pi / 180))
            headingY = math.cos((self.rotation + 90) * (math.pi / 180))
            heading = (-headingX * self.side_speed, -headingY * self.side_speed)
            self.rect.move_ip(heading)
        if self.keyboard.right == True and self.mouse_over == False:
            headingX = math.sin((self.rotation + 90) * (math.pi / 180))
            headingY = math.cos((self.rotation + 90) * (math.pi / 180))
            heading = (headingX * self.side_speed, headingY * self.side_speed)
            self.rect.move_ip(heading)
        # clamp player inside screen
        self.rect = self.rect.clamp(pygame.Rect(self.SCREEN_RECT))
